package edu.westga.cs3152.project2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * The SpellCheckDriver creates a SpellChecker, a SpellingSuggestor, 
 * and prompts the user for a document to be spell checked. 
 * 
 * @author Lewis Williams
 * @version 2011.3.20
 */
public class SpellCheckDriver {
	
	private static boolean quit = false;
	private static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {
		String userInput = "";
		//The SpellChecker that will spell check the document
		SpellChecker spellChecker = new SpellChecker();
		//The SpellingSuggestor that will offer possible corrections to misspelled words
		SpellingSuggestor spellingSuggestor = new SpellingSuggestor();
		
		while(quit == false){
			System.out.println("Enter the name of the file you would like spell checked or 'quit' to exit: ");
			userInput = scan.nextLine();
			
			if(userInput.equalsIgnoreCase("quit")){
				quit = true;
			}
			else{
				spellChecker.checkSpelling(userInput);
				ArrayList<String> misspelledWords = new ArrayList<String>(spellChecker.getMisspelledWords());
				Iterator<String> misspelledWordsIterator = misspelledWords.iterator();
				System.out.println("Misspelled Words: ");
				while(misspelledWordsIterator.hasNext()){
					String word = misspelledWordsIterator.next();
					System.out.println(word + " | possible corrections: " + spellingSuggestor.getReplacementWords(word));
				}
			}
			System.out.println("");
		}
		System.out.println("Program Done :-)");
	}
}
